<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>背景轮播示例</title>
    <style>
        .header {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 60px;
            background: rgba(0,0,0,0.5);
            display: flex;
            align-items: center;
            padding: 0 20px;
            z-index: 1000;
        }

        .header img:first-child {
            height: 40px;
            margin-right: 25%;
        }

        .header nav {
            display: flex;
            gap: 20px;
            flex: 1;               /* 占满中间区域 */
        }

        .header a {
            color: white;
            text-decoration: none;
            font-size: 20px;
            line-height: 60px;
            font-weight: bold;
        }
        .header a:hover {
            text-decoration: underline;
        }

        .header img:last-child {
            height: 30px;
            margin-left: auto;      /* 自动推到最右 */
            margin-right: 30px;
            cursor: pointer;
        }


        /* 背景轮播容器 */
        .body {
            margin-top: 60px;
            width: 100%;
            height: 100vh;
            background-size: cover;
            background-position: center;
            transition: background-image 1s ease-in-out;
            position: relative;
        }

        /* 小圆点容器 */
        .dots {
            position: absolute;
            bottom: 30px;
            left: 50%;
            bottom: 20%;
            transform: translateX(-50%);
            display: flex;
            gap: 10px;
        }

        /* 小圆点样式 */
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: rgba(255,255,255,0.6);
            cursor: pointer;
            transition: background 0.3s;
        }

        .dot.active {
            background: white;
        }
        .search{
            position: absolute;
            width: 1000px;
            height: 100px;
            background-color: white;
            left: 20%;
            bottom: 0;

        }
        .search input {
            flex: 1;
            height: 100%;
            border: none;
            outline: none;
            font-size: 36px;
            text-indent: 30px;
            padding: 0 15px;
            border-radius: 30px;
            background: transparent;

        }
        .search button {
            position: absolute;
            width: 60px;
            height: 60px;
            border: none;
            border-radius: 50%;
            background: #EEEEEE url("image/搜索.png") no-repeat center/20px 20px;
            cursor: pointer;
            transition: background 0.3s;
            right: 10%;
            top: 20%;
        }
        .search input::placeholder {
            color: purple;
            opacity: 0.7;   /* 可以让提示比输入内容浅一点 */
        }
    </style>
</head>
<body>
<div class="header">
    <img src="image/logo-white.png" alt="logo">

    <nav>
        <a href="#">清华新闻</a>
        <a href="#">学校概况</a>
        <a href="#">院系设置</a>
        <a href="#">教育教学</a>
        <a href="#">科学研究</a>
        <a href="#">招生就业</a>
        <a href="#">合作交流</a>
        <a href="#">走进清华</a>
    </nav>

    <img src="image/更多.png" alt="更多">
</div>

<div class="body" id="slideshow">
    <div class="dots" id="dots"></div>
    <div class="search">
        <input type="text" placeholder="快速探索Tinghua University" >
        <button style="background-image: url(image/搜索.png)"></button>
        <hr>
    </div>

</div>

<script>
    const images = [
        "image/1.jpg",
        "image/2.jpg",
        "image/3.jpg"
    ];

    let index = 0;
    const slideshow = document.getElementById("slideshow");
    const dotsContainer = document.getElementById("dots");

    images.forEach((_, i) => {
        const dot = document.createElement("div");
        dot.classList.add("dot");
        if (i === 0) dot.classList.add("active");
        dot.addEventListener("click", () => {
            index = i;
            updateSlideshow();
            resetInterval();
        });
        dotsContainer.appendChild(dot);
    });

    const dots = document.querySelectorAll(".dot");

    function updateSlideshow() {
        slideshow.style.backgroundImage = `url(${images[index]})`;
        dots.forEach((dot, i) => {
            dot.classList.toggle("active", i === index);
        });
    }

    function nextImage() {
        index = (index + 1) % images.length;
        updateSlideshow();
    }

    let timer = setInterval(nextImage, 3000);

    function resetInterval() {
        clearInterval(timer);
        timer = setInterval(nextImage, 3000);
    }

    updateSlideshow();
</script>
</body>
</html>
